Page({
  data: {
    shows: 1,
    scrollText: ['请点击开始抽奖', 'MAC口红 一支', '谢谢参与', '小米蓝牙音箱 一个', '谢谢参与', '漫步者蓝牙耳机 一套', '小米蓝牙音箱 一个', 'MAC口红 一支', '谢谢参与', '谢谢参与'], // 滚动的文字
    animationData: null // 绑定的动画效果
  },
  onLoad: function (options) {
    // var that = this;
    // var num =  Math.random() * 6
    // console.log(num)
    // var index = num >> 0
    // console.log(that.data.scrollText[index])
    // that.setData({
    //   aaaa:that.data.scrollText[index]
    // })

  },
  submit() {

  },
  onReady: function () {

  },
  onShow: function () {

  },
  onHide: function () {

  },
  onUnload: function () {},
  startScroll() {
    var that = this;
    console.log('开启')
    // 创建一个动画实例
    let animation = wx.createAnimation({
      duration: 6500,
      timingFunction: 'ease'
    })
    // 获取元素总高度
    let height = (this.data.scrollText.length - 1) * 200
    // 向上移动
    animation.translateY(-height + 'rpx').step()
    // 将动画效果赋值
    this.setData({
      animationData: animation.export(),
    })
    setTimeout(
      (res) => {
        var phone = wx.getStorageSync('phone')
        wx.request({ //发送请求
          url: 'https://zg99.offcn.com/index/choujiang/getcjusers?actid=38495&callback=?', //接收url
          data: {
            phone: phone,
            limits: 100
          }, //接收参数
          success(res) {
            var jsonStr = res.data;
            jsonStr = jsonStr.replace("(", "");
            jsonStr = jsonStr.replace(")", "");
            if (typeof jsonStr != 'object') {
              jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
              var theJson = JSON.parse(jsonStr);
            }
            console.log(theJson)
            if (theJson.status === 2) {
              wx.request({ //发送请求
                url: 'https://zg99.offcn.com/index/choujiang/lottery?actid=38495&callback=?', //接收url
                data: {
                  phone: phone,
                }, //接收参数
                success(res) {
                  var jsonStr = res.data;
                  jsonStr = jsonStr.replace("(", "");
                  jsonStr = jsonStr.replace(")", "");
                  if (typeof jsonStr != 'object') {
                    jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
                    var theJson = JSON.parse(jsonStr);
                  }
                  console.log(theJson)
                  var prizeid = theJson.prizeid
                  if(prizeid != 4){
                    that.setData({
                      aaaa: '恭喜获得' + theJson.prizename,
                      jiang: true,
                      shows: !1,
                      isRunning: false,
                      add:1
                    })
                  } else {
                    that.setData({
                      aaaa: theJson.prizename,
                      jiang: true,
                      shows: !1,
                      isRunning: false,
                    })
                  }
                  
                }
              })
            } else if (theJson.status === 1) {
              console.log(theJson.lists[0].prizeid)
              var aaaa =  theJson.lists[0].prizename
              if(theJson.lists[0].prizeid != 4){
                that.setData({
                  aaaa,
                  shows: !1,
                  add:1
                }) 
              } else {
                that.setData({
                  aaaa,
                  shows: !1,
                }) 
              }
              
              
            } else {
              console.log(1110)
              that.setData({
                aaaa: '次数不足，您已经抽过奖了',
                shows: !1
              })
            }
          }
        })
      }, 5000
    )


  },
  animationend() {
    var _this = this;
    _this.startGame();
  },
  // 重置
  reset() {
    let animation = wx.createAnimation({
      duration: 0
    })
    this.setData({
      animationData: animation.translateY(0).step().export()
    })
  },
  //开始抽奖
  startGame: function () {
    var that = this;

  },
  nameInput: function (e) {
    this.setData({
      name: e.detail.value
    })
    wx.setStorageSync('name', e.detail.value)
    console.log(this.data.name)
  },
  next() {
    var that = this;
    var phone = wx.getStorageSync('phone')
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/biaodan/register?actid=39014&callback=?', //接收url
      data: {
        phone: phone,
        address: that.data.name
      }, //接收参数
      success(res) {
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        console.log(theJson)
        wx.showToast({
          title: '提交成功',
        })
        that.setData({
          add:!1
        })
      }
    });
  },


})